// packageA/pages/debtorList.ts
import { getDebtorListApi } from "../../../api/debtor"

Page({
  /**
   * 页面的初始数据
   */
  data: {
    labelList: [
      { label: "地区", key: "provinceName" },
      { label: "财产线索", key: "clueNum" },
      { label: "财产线索价值", key: "clueAmount" },
      { label: "担保人", key: "guarantorNum" },
      { label: "次债务人线索", key: "assetClueNum" },
      { label: "涉诉线索", key: "lawsuitClueNum" },
    ],
    companyName: "",
    page: 1,
    perPage: 10,
    pageList: [],
    total: 0,
    listLoading: false,
    reLoading: false
  },
  getList(oper?: string) {
    if (oper === 'refresh') {
      this.setData({
        reLoading: true
      })
    }
    this.setData({
      listLoading: true
    })
    let para = {
      page: this.data.page,
      perPage: this.data.perPage,
      companyName: this.data.companyName,
      companyType: 1, // 债务人
      verifyStatus: 1, //审核通过
    }
    let pageList = this.data.pageList.slice();
    getDebtorListApi(para).then((res: any) => {
      if (res.code === '000') {
        if (res.content.list && res.content.list.length > 0) {
          res.content.list.forEach((item: any) => {
            item.createTime = item.createTime ? item.createTime.slice(0, 10) : '-';
          });
        }
        this.setData({
          pageList: pageList.concat(res.content.list || []),
          total: res.content.total,
          listLoading: false
        })
        if (oper === 'refresh') {
          this.setData({
            reLoading: false
          })
        }
      }
    })
  },
  reset() {
    this.data.page = 1;
    this.setData({
      pageList: []
    })
  },
  // 下拉刷新
  bindrefresherrefresh() {
    this.reset();
    this.getList("refresh");
  },
  // 上拉更新
  scrollToLowerHandle() {
    if (this.data.total > this.data.pageList.length) {
      this.data.page++;
      this.getList();
    }
  },
  // 搜索
  searchFunc() {
    this.reset();
    this.getList();
  },
  // 点击跳转债务人详情
  skipTo(e: any) {
    const { id, companyname } = e.currentTarget.dataset;
    wx.navigateTo({
      url: "/subPackages/packageA/debotrDetail/debtorDetail?debtorId=" + id + "&companyName=" + companyname
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },


})